/*
 * @Author: szx
 * @Date: 2022-06-14 12:08:32
 * @LastEditTime: 2022-06-14 12:20:20
 * @Description:
 * @FilePath: \leetcode\面试题\17\10\10.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
 var majorityElement = function (nums) {
    let res = -1,
        cnt = 0;
    for (let num of nums) {
        if (cnt === 0) res = num;
        if (num == res) cnt++;
        else cnt--;
    }
    if (nums.reduce((p, c) => p + (c === res), 0) > Math.floor(nums.length / 2)) return res
    return -1;
};
